package com.hdsx.netty.monitor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author 占贤银
 * time 2024/8/9 0:43
 * description 生命之灯因热情而点燃，生命之舟因拼搏而前行
 */
public class BioMonitor implements InvocationHandler {

    private Object puaseObject;

    public BioMonitor(Object puaseObject) {
        this.puaseObject = puaseObject;
    }

    public <T> T create(Class<T> aclazz) {
        return (T) Proxy.newProxyInstance(aclazz.getClassLoader(), aclazz.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) {
        try {
            System.out.println("start minotor：" + System.currentTimeMillis());
            System.out.println("methodName = " + method.getDeclaringClass());
            Object result = method.invoke(this.puaseObject, args);
            System.out.println("end minotor：" + System.currentTimeMillis());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
